package edu.fdzc.system.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import edu.fdzc.system.entity.Accout;
import edu.fdzc.system.entity.Course;
import edu.fdzc.system.mapper.CourseMapper;
import edu.fdzc.system.service.CourseService;
import edu.fdzc.system.utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {

    @Autowired
    private CourseMapper courseMapper;

    @Override
    public void add(Course course) {
        Accout currentUser = TokenUtils.getCurrentUser();
        course.setTeacherId(currentUser.getId());
        courseMapper.insert(course);
    }

    @Override
    public void updateById(Course course) {
        courseMapper.updateById(course);
    }

    @Override
    public void deleteById(Integer id) {
        courseMapper.deleteById(id);
    }

    @Override
    public void deleteBatch(List<Integer> ids) {
        for(Integer id : ids){
            courseMapper.deleteById(id);
        }
    }

    @Override
    public Course selectById(Integer id) {
        return courseMapper.selectById(id);
    }

    @Override
    public List<Course> selectAll(Course course) {
        return courseMapper.selectAll(course);
    }

    @Override
    public PageInfo<Course> selectPage(Course course, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Course> list = courseMapper.selectAll(course);
        return new PageInfo<>(list);
    }
}
